package com.jeff.tianti.controller;

import com.jeff.tianti.common.ueditor.ActionEnter;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@RestController
@RequestMapping("ueditor")
@CrossOrigin(maxAge = 3600)
public class ConfigController {
    @RequestMapping("/config")
    public void getUEditorConfig(HttpServletResponse response, HttpServletRequest request) throws Exception{
        response.setContentType("application/json");
        String rootPath = request.getSession().getServletContext().getRealPath("/");
        try {
            String exec = "";
            request.setCharacterEncoding("utf-8");
            exec = new ActionEnter(request, rootPath).exec();

            PrintWriter writer = response.getWriter();
            writer.write(exec);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
